package com.itheima.d7_interface_demo;

import java.util.ArrayList;

public class StudentOperatorlmol2 implements StudentOperator {
    @Override
    public void printAll(ArrayList<Student> stu) {
        System.out.println("------------打印全部学生信息----------------");
        int count1 = 0;
        int count2 = 0;
        for (int i = 0; i < stu.size(); i++) {
            Student s1 = stu.get(i);
            if(s1.getSex() == '男'){
                count1++;
            }else {
                count2++;
            }
//            System.out.println(s1.getName() + s1.getSex() + s1.getScore());
            System.out.println(s1.toString());
        }

        System.out.println("男生人数是"+count1+"女生人数是"+count2);
    }

    @Override
    public void printAvgScore(ArrayList<Student> stu) {
        System.out.println("------------打印学生平均成绩----------------");
        double max = 0;
        double min = 0;
        double allScore = 0;
        for (int i = 0; i < stu.size(); i++) {
            Student s1 = stu.get(i);
            if(s1.getScore() > max){
                max = s1.getScore();
            }
            if(s1.getScore() < min){
                min = s1.getScore();
            }
            allScore += s1.getScore();
        }
        System.out.println("最大成绩是"+max);
        System.out.println("最小成绩是"+min);
        System.out.println("平均成绩是"+allScore);
    }
}
